package com.yywq.service.impl;

import com.yywq.error.BusinessException;
import com.yywq.error.EnumBusinessError;
import com.yywq.mapper.OrderTimeMapper;
import com.yywq.pojo.OrderTime;
import com.yywq.service.OrderTimeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/**
 * @author: 吴磊
 * @program: yywq_parent
 * @create: 2021-04-15 18:45
 */
@Service
public class OrderTimeServiceImpl implements OrderTimeService {
    @Autowired
    private OrderTimeMapper orderTimeMapper;

    @Override
    public OrderTime getOrderTimeByOid(String oid) {
        if (StringUtils.isEmpty(oid)) {
            throw new BusinessException(EnumBusinessError.PARAMETER_INVALID_ERROR, "订单不存在或则订单ID有问题");
        }
        OrderTime orderTime;
        try {
            orderTime = orderTimeMapper.getOrderTimeByOid(oid);
            if (orderTime == null) {
                throw new BusinessException(EnumBusinessError.UNKNOWN_ERROR, "订单不存在");
            }
        } catch (Exception e) {
            throw new BusinessException(EnumBusinessError.UNKNOWN_ERROR, "查询订单失败");
        }
        return orderTime;
    }
}
